package sg.edu.nus.iss.umpire.service.workflow.dto;

import java.util.ArrayList;
import java.util.List;

import sg.edu.nus.iss.umpire.domain.Session;

import com.google.appengine.api.datastore.KeyFactory;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class SessionDTO {
		private String date;
		private String slotName;
		private String key;
		
		private List<Long> confirmedUmpire = new ArrayList<Long>();
		private List<Long> availUmpire = new ArrayList<Long>();
		
		
		public String getKey() {
			return key;
		}
		public void setKey(String key) {
			this.key = key;
		}
		public String getDate() {
			return date;
		}
		public void setDate(String date) {
			this.date = date;
		}
		public String getSlotName() {
			return slotName;
		}
		public void setSlotName(String slot) {
			this.slotName = slot;
		}
		
		public List<Long> getConfirmedUmpire() {
			return confirmedUmpire;
		}
		public void setConfirmedUmpire(List<Long> confirmedUmpire) {
			this.confirmedUmpire = confirmedUmpire;
		}
		public List<Long> getAvailUmpire() {
			return availUmpire;
		}
		public void setAvailUmpire(List<Long> availUmpire) {
			this.availUmpire = availUmpire;
		}
		
		public static List<SessionDTO> fromJSON(String json){
			Gson gson = new Gson();
	    	return gson.fromJson(json, new TypeToken<List<SessionDTO>>(){}.getType());
		}
		
		public static SessionDTO fromEntity(Session session){
			if (session == null)
				return new SessionDTO(); // return non-null empty object to make UI easier
			
			SessionDTO dto = new SessionDTO();
			dto.setKey(KeyFactory.keyToString(session.getSessionKey()));
			dto.setSlotName(session.getSlotName());
			dto.setAvailUmpire(session.getAvailUmpire());
			dto.setConfirmedUmpire(session.getConfirmedUmpire());
			return dto;
		}	
		
}
